package com.guochuang.yunwang.promanager.utils;


import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 项目工具类
 * @author hk
 */
public class ProjectUtils {

    /**
     * 进行md5加密
     * @return
     */
    public static String md5(String passwd){

        if(passwd==null||passwd.length() == 0){
            throw new RuntimeException("参数错误！");
        }
        try {
            String algorithm = "md5";

            MessageDigest md5 = MessageDigest.getInstance(algorithm);

            byte[] bytes = passwd.getBytes();

            byte[] password = md5.digest(bytes);

            // 将字节数组转化为字符串

            int signum = 1;  // 表示为正数

            BigInteger bigInteger = new BigInteger(signum,password);

            int radix = 16; // 表示为16进制

            String pas= bigInteger.toString(radix).toUpperCase();

            return pas;

        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("加密失败！");
        }
    }
}
